import { get, post, put, del } from '@/utils/request'
import type { TalkForm, TalkQuery, TalkItem, PageResult, Tag } from '@/types/talk'

// 说说相关API
export const talkApi = {
  // 获取说说列表
  getTalkList: (params: TalkQuery) => {
    return get<PageResult<TalkItem>>('/talk/list', params)
  },

  // 获取说说详情
  getTalkDetail: (talkId: number) => {
    return get<TalkForm>(`/talk/form/${talkId}`)
  },

  // 发布说说
  addTalk: (data: TalkForm) => {
    return post('/talk/add', data)
  },

  // 更新说说
  updateTalk: (data: TalkForm) => {
    return put('/talk/update', data)
  },

  // 删除说说
  deleteTalk: (talkIds: number[]) => {
    console.log('API调用 - 删除说说，talkIds:', talkIds)
    const url = `/talk/delete?talkIds=${talkIds.join(',')}`
    console.log('删除URL:', url)
    return del(url)
  }
}

// 标签相关API
export const tagApi = {
  // 获取标签列表
  getTagList: (tagType: number = 1) => {
    return get<Tag[]>(`/tag/list?tagType=${tagType}`)
  },

  // 添加标签
  addTag: (data: { tagName: string; tagType: number }) => {
    return post('/tag/add', data)
  },

  // 更新标签
  updateTag: (data: { id: number; tagName: string; tagType: number }) => {
    return put('/tag/update', data)
  },

  // 删除标签
  deleteTag: (tagIds: number[]) => {
    return del(`/tag/delete/${tagIds.join(',')}`)
  }
}
